package frontend.parser.node.decl;

import frontend.lexer.token.Token;
import frontend.parser.node.Node;
import frontend.parser.node.TokenNode;
import frontend.parser.node.expnode.ConstExp;

public class VarDef extends Node {
    // 变量定义    VarDef → Ident { '[' ConstExp ']' } // b
    //    | Ident { '[' ConstExp ']' } '=' InitVal // k
    private TokenNode identTokenNode;
    private int dimension = 0;
    private ConstExp[] dimLenConstExp = new ConstExp[2];
    private boolean hasInitVal = false;
    private InitVal initVal;
    public void addIdentTokenNode(TokenNode identTokenNode) {
        super.add(identTokenNode);
        this.identTokenNode = identTokenNode;
    }
    public void addDimLenConstExp(ConstExp lenConstExp) {
        super.add(lenConstExp);
        if (dimension < 2) {
            dimLenConstExp[dimension++] = lenConstExp;
        }
    }
    public void addInitVal(InitVal initVal) {
        super.add(initVal);
        this.hasInitVal = true;
        this.initVal = initVal;
    }

    public TokenNode getIdentTokenNode() {
        return identTokenNode;
    }

    public int getDimension() {
        return dimension;
    }

    public ConstExp[] getDimLenConstExp() {
        return dimLenConstExp;
    }

    public boolean hasInitVal() {
        return hasInitVal;
    }

    public InitVal getInitVal() {
        return initVal;
    }

    public String getIdentName() {
        return identTokenNode.getContent();
    }

    public Token getIdentToken() {
        return identTokenNode.getToken();
    }

    // symbol manager

//    private VarSymbol varSymbol;
//    public VarSymbol toVarSymbol() {
//        return (this.varSymbol =
//                new VarSymbol(identTokenNode, dimension, dimLenConstExp, initVal, hasInitVal));
//    }
//
//    public VarSymbol getVarSymbol() {
//        return varSymbol;
//    }
}
